package com.manage.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manage.platform.entity.AchieveTaskEntity;
import com.manage.platform.mapper.AchieveTaskMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * YWD
 * 2025/11/19
 */
@AllArgsConstructor
@Service
public class AchieveTaskServiceImpl extends ServiceImpl<AchieveTaskMapper, AchieveTaskEntity> {

    public Boolean saveList(Long achieveId, List<Long> taskList) {
        List<AchieveTaskEntity> list = taskList.stream().map(it -> {
            AchieveTaskEntity entity = new AchieveTaskEntity();
            entity.setAchieveId(achieveId);
            entity.setTaskId(it);
            return entity;
        }).toList();
        return this.saveBatch(list);
    }

    public Boolean removeByAchieveId(Long achieveId) {
        LambdaQueryWrapper<AchieveTaskEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AchieveTaskEntity::getAchieveId, achieveId);
        return this.remove(queryWrapper);
    }
}
